import { getProbability,  IArticle } from './utils.tsx'

async function renderHeader(articleElement: IArticle): Promise<void> {
    const result = await getProbability(articleElement.HTMLNoKaTeX);
    if ((articleElement.head?.nextElementSibling?.previousSibling) != null) articleElement.head.nextElementSibling.previousSibling.textContent = '对应题目：'
    const $header: JQuery<HTMLElement> = $(articleElement.head)
    let headDiv = document.createElement(`span`);
    let solutionHref = document.createElement(`a`);
    solutionHref.href = `/problem/solution/${articleElement.pid}`;
    solutionHref.target = `_blank`;
    solutionHref.innerText = `\ \ 题解区`;
    headDiv.append(' | ')
    headDiv.appendChild(solutionHref);
    headDiv.appendChild(document.createElement(`br`));

    let otherShowSpan = document.createElement(`span`);
    let AISpan = document.createElement(`span`);
    AISpan.setAttribute(`style`, `color: ${result >= 50 ? '#fb6340' : '#2dce89'}; font-size: 2rem`);
    AISpan.className = `am-article-meta-chatgpt`;
    AISpan.append(`${result.toFixed(2)}% AI`);

    let DiffSpan = document.createElement(`span`);
    DiffSpan.innerHTML = `<a href="#" id = "Diff${articleElement.blogid}" class="DiffPoint">0.00%</a>`
    otherShowSpan.appendChild(AISpan);
    otherShowSpan.append(" | ")
    otherShowSpan.appendChild(DiffSpan);
    headDiv.appendChild(otherShowSpan);
    $header.next().after(headDiv);
    $header.next().before(`<strong class="exadmin-difficulty-color color-${articleElement.color}">${articleElement.pid}</strong>`)
    $header.after(`博客管理：<a href="/blog/_post/${articleElement.blogid}" target="_blank">博客链接</a> | <a href="/webadmin/blog/editArticle/${articleElement.blogid}" target="_blank">后台编辑</a><br/>`)
}
export { renderHeader }
